package com.lxmes.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.lxmes.business.domain.NcQualityCertificationProcess;
import com.lxmes.business.service.INcQualityCertificationProcessService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;

/**
 * 质量认证流程Controller
 * 
 * @author lx
 * @date 2023-06-01
 */
@Api(tags = "质量认证流程")    
@RestController
@RequestMapping("/business/NcQualityCertificationProcess")
public class NcQualityCertificationProcessController extends BaseController
{
    @Autowired
    private INcQualityCertificationProcessService ncQualityCertificationProcessService;

    /**
     * 查询质量认证流程列表
     */
    @ApiOperation("查询质量认证流程列表")
    @PreAuthorize("@ss.hasPermi('business:NcQualityCertificationProcess:list')")
    @GetMapping("/list")
    public TableDataInfo list(NcQualityCertificationProcess ncQualityCertificationProcess)
    {
        startPage();
        List<NcQualityCertificationProcess> list = ncQualityCertificationProcessService.selectNcQualityCertificationProcessList(ncQualityCertificationProcess);
        return getDataTable(list);
    }

    /**
     * 导出质量认证流程列表
     */
    @ApiOperation("导出质量认证流程列表")
    @PreAuthorize("@ss.hasPermi('business:NcQualityCertificationProcess:export')")
    @Log(title = "质量认证流程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NcQualityCertificationProcess ncQualityCertificationProcess)
    {
        List<NcQualityCertificationProcess> list = ncQualityCertificationProcessService.selectNcQualityCertificationProcessList(ncQualityCertificationProcess);
        ExcelUtil<NcQualityCertificationProcess> util = new ExcelUtil<NcQualityCertificationProcess>(NcQualityCertificationProcess.class);
        util.exportExcel(response, list, "质量认证流程数据");
    }

    /**
     * 获取质量认证流程详细信息
     */
    @ApiOperation("获取质量认证流程详细信息")
    @PreAuthorize("@ss.hasPermi('business:NcQualityCertificationProcess:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ncQualityCertificationProcessService.selectNcQualityCertificationProcessById(id));
    }

    /**
     * 新增质量认证流程
     */
    @ApiOperation("新增质量认证流程")
    @PreAuthorize("@ss.hasPermi('business:NcQualityCertificationProcess:add')")
    @Log(title = "质量认证流程", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NcQualityCertificationProcess ncQualityCertificationProcess)
    {
        return toAjax(ncQualityCertificationProcessService.insertNcQualityCertificationProcess(ncQualityCertificationProcess));
    }

    /**
     * 修改质量认证流程
     */
    @ApiOperation("修改质量认证流程")
    @PreAuthorize("@ss.hasPermi('business:NcQualityCertificationProcess:edit')")
    @Log(title = "质量认证流程", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NcQualityCertificationProcess ncQualityCertificationProcess)
    {
        return toAjax(ncQualityCertificationProcessService.updateNcQualityCertificationProcess(ncQualityCertificationProcess));
    }

    /**
     * 删除质量认证流程
     */
    @ApiOperation("删除质量认证流程")
    @PreAuthorize("@ss.hasPermi('business:NcQualityCertificationProcess:remove')")
    @Log(title = "质量认证流程", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ncQualityCertificationProcessService.deleteNcQualityCertificationProcessByIds(ids));
    }
    /**
     * 导入质量认证流程
     */
    @Log(title = "质量认证流程", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<NcQualityCertificationProcess> util = new ExcelUtil<>(NcQualityCertificationProcess.class);
        List<NcQualityCertificationProcess> ncQualityCertificationProcessList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = ncQualityCertificationProcessService.imporIteminfo(ncQualityCertificationProcessList, updateSupport, operName);
        return AjaxResult.success(message);
    }
    // 下载模板
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) throws IOException
    {
        ExcelUtil<NcQualityCertificationProcess> util = new ExcelUtil<>(NcQualityCertificationProcess.class);
        util.importTemplateExcel(response,"质量认证流程");
    }
}
